<template>
    <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="sid"
        label="商家id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="sname"
        label="商家名称"
        width="180">
      </el-table-column>
     <el-table-column
        label="操作"
        width="100">
      <template slot-scope="scope">
        <el-button @click="sellersDelete(scope.row)" type="text" size="small">删除</el-button>
        <el-button @click="sellersFind(scope.row)" type="text" size="small">编辑</el-button>
      </template>
     </el-table-column>
    </el-table>
    <el-pagination
      background
      current-page
      page-size=3
      prev-page="上一页"
      next-page="下一页"
      @current-change="currentPage"
      layout="prev, pager, next , jumper, total"
      :total="total">
    </el-pagination>
    </div>
  </template>

  <script>
    export default {
    methods: {
        currentPage(page) {
            let _this = this
            axios.get('http://localhost:8888/chuyangc/sellers/pagelist/' + page).then(function (response){
            _this.total = response.data.total
            _this.tableData = response.data.list
        })
        },
        sellersDelete(row) {
        let _this = this
        this.$confirm('是否确认要删除'+row.sname+'?', '删除数据', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
                let url = "http://localhost:8888/chuyangc/sellers/delete/" + row.sid
                axios.delete(url).then(function (response) {
                if (response.data) {
                    _this.$alert(row.sname + "删除成功",'删除数据',{
                    confirmButtonText: '确定',
                    callback: action => {
                        location.reload()
                    }
                    });
                }
                })
            }
            ).catch(() => {
        });
        },
        sellersFind(row){
            this.$router.push('/sellersedit?sid=' + row.sid)
        }
    },
    created() {
        let _this = this
        axios.get('http://localhost:8888/chuyangc/sellers/pagelist/1').then(function (response){
            _this.total = response.data.total
            _this.tableData = response.data.list
        })
    },
    data() {
        return {
            tableData: null,
            total:0
        }
    }
    }
</script>